#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=110;
int n,m,e[MAXN][MAXN],match[MAXN];
bool vis[MAXN];
bool Hungary(int u)
{
	for(int v=1;v<=n;++v)
	{
		if(e[u][v]&&!vis[v])
		{
			vis[v]=true;
			if(!match[v]||Hungary(match[v]))
			{
				match[v]=u;
				return true;
			}
		}
	}
	return false;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read(),y=read();
		e[x][y]=1;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				e[i][j]|=e[i][k]&e[k][j];
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		memset(vis,0,sizeof(vis));
		if(Hungary(i))++ans;
	}
	printf("%d\n",n-ans);
	return 0;
}
